from selenium import webdriver
from selenium.webdriver.common.by import By
import time
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

driver = webdriver.Firefox()
time.sleep(2)
driver.get('https://www.baidu.com/')
news = WebDriverWait(driver,20,0.5).until(EC.presence_of_element_located((By.LINK_TEXT,'新闻')))
news.click()
driver.switch_to.window(driver.window_handles[-1])
driver.implicitly_wait(10)
driver.find_element(By.PARTIAL_LINK_TEXT,'心相近').click()
driver.switch_to.window(driver.window_handles[-1])
time.sleep(15)
# 向下滚动1000像素
# driver.execute_script('window.scrollTo(0,1000)')
# time.sleep(2)
print(1)
target=driver.find_element(By.XPATH,'//*[@id="app"]/div[3]/div[2]/div/span')
print(1.5)

driver.execute_script("arguments.scrollIntoView();",target)
print(2)

time.sleep(5)
driver.find_element(By.XPATH,'//*[@id="app"]/div[1]/div[3]/div[2]/div/span').click()
# 滚动到底部
driver.execute_script('window.scrollTo(0,document.body.scrollHeight)')
time.sleep(2)
# 滚动到顶部
driver.execute_script('widnow.scrollTo(0,0)')
time.sleep(10)